<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function buyPen(){
            return new Promise((resolve,reject)=>{
                setTimeout(function(){
                    resolve('买笔成功')
                },3000)
            })
        }

        function buyNone(){
            return new Promise((resolve,reject)=>{
                setTimeout(function(){
                    resolve('买本成功')
                },2000)
            })
        }

        //等待所有的异步函数全部执行完毕才返回
        Promise.all([buyPen(),buyNone()]).then((result)=>{
            console.log(result);
        })
        //最先执行的异步函数
        Promise.race([buyPen(),buyNone()]).then((result)=>{
            console.log(result);
        })
    </script>
</body>
</html>